package meijuli.com.join51.business.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import meijuli.com.join51.business.R;
import meijuli.com.join51.business.fragment.ClassificationFragment;

/**
 * 分类管理页
 *
 * @author wenqin 2017-04-25 13:57
 */

public class ClassificationActivity extends BaseActivity {
    public static final String KEY_FORM = "form_page";
    TextView mToolbarTitle;
    TextView mTextMenu;
    Toolbar mToolbar;

    private OnMenuTextClick mOnMenuTextClick;
    private String mFormPage = "";

    public void setOnMenuTextClick(OnMenuTextClick onMenuTextClick) {
        mOnMenuTextClick = onMenuTextClick;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_fragment);
        mToolbarTitle = findViewById(R.id.toolbar_title);
        mTextMenu = findViewById(R.id.text_menu);
        mToolbar = findViewById(R.id.toolbar);
        if(getIntent() != null) {
            mFormPage = getIntent().getStringExtra(KEY_FORM);
        }
        initToolBar();
        addFragment(ClassificationFragment.newInstance(mFormPage));
    }

    private void initToolBar() {
        if(!TextUtils.isEmpty(mFormPage) && AddCommodityActivity.class.getName().equals(mFormPage)) {
            mToolbarTitle.setText("选择分类");
        } else {
            mToolbarTitle.setText("分类管理");
        }
        mToolbar.setNavigationIcon(R.mipmap.icon_back_white);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mTextMenu.setText("添加");
        mTextMenu.setVisibility(View.VISIBLE);
        mTextMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnMenuTextClick != null) {
                    mOnMenuTextClick.onMenuTextClick();
                }
            }
        });
    }

    public interface OnMenuTextClick{
        /**
         * 菜单文本点击事件
         */
        void onMenuTextClick();
    }
}
